package com.focusmes.modules.base.workshop.component;

import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.online.cgform.enhance.CgformEnhanceJavaListInter;
import org.jeecg.modules.online.cgform.mapper.OnlCgformFieldMapper;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.springframework.stereotype.Component;
import sun.security.smartcardio.SunPCSC;

import java.util.*;

@Component("enWorkshopList")
public class EnWorkshopList implements CgformEnhanceJavaListInter {

    @Override
    public void execute(String tableName, List<Map<String, Object>> data) throws BusinessException {

        List<Map<String, Object>> listMaps = MesFactoryData();
        for (Map<String, Object> map : data) {
            Object db = map.get("factory_id");
            if(db==null){
                continue;
            }
            for (Map<String, Object> lmap : listMaps) {
                for (Map.Entry<String, Object> m : lmap.entrySet()) {
                    if(m.getKey().equals(db)){
                        map.put("factory_id",m.getValue());
                    }
                }
            }
        }


    }
    /**
     * 获取工厂列表
     * @return
     */
    private List<Map<String, Object>> MesFactoryData(){
        OnlCgformFieldMapper onlCgformFieldMapper = SpringContextUtils.getBean(OnlCgformFieldMapper.class);
        String sqlStr = "select * from mes_factory ";
        List<Map<String, Object>> list = onlCgformFieldMapper.queryListBySql(sqlStr);
        return list;
    }


}